﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;

public partial class controls_admin_RSSFeedsAdd : Admin_Controls_Base {
    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            bindDDL(ddlCategories, BO_portal_categories.SelectByParent(0, 1), "FULL_CATEGORY_NAME", "CATEGORY_ID");
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e) {
        string strConfig = ConfigurationManager.AppSettings["RSS_FEEDS_LINK"].ToString();
        strConfig = strConfig.Replace("$FEED_TITLE", StringUtils.RemoveUnicode(txtFeedTitle.Text, "-"));
        strConfig = strConfig.Replace("$CATEGORY_ID", ddlCategories.SelectedValue);
        try {
            string result = BO_portal_rss_feeds.Insert(txtFeedTitle.Text, int.Parse(ddlCategories.SelectedValue), strConfig, ddlContents.SelectedValue, int.Parse(txtSortDisplay.Text), DateTime.Now, Administrator.USER_NAME, DateTime.Now, Administrator.USER_NAME, true);
            if (result == "0") {
                divMessage.InnerHtml = MessageBox.Error("Hệ thống", "Thực hiện không thành công");
            } else {
                divMessage.InnerHtml = MessageBox.Success("Hệ thống", "Thêm mới thành công");
            }
            Clear(this.Controls);
        } catch (Exception ex) {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message);
        }
    }
}
